package com.demo.flowable;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 银行业务流程
 * @author K
 */
@Slf4j
@Component
public class FlowableBlankService {

    @Resource
    private RuntimeService runtimeService;

    /**
     * 服务任务
     * @param vars
     */
    public void transfer(Map<String,Object> vars) {
        //流程定义的key,对应请假的流程图
        String processDefinitionKey = "transfer";
        //业务代码，根据自己的业务用
        String businessKey = "transfer";
        runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, vars);
    }

    /**
     * 使用委托表达式
     * @param vars 流程参数
     */
    public void transferDelegateExpression(Map<String,Object> vars) {
        //流程定义的key,对应请假的流程图
        String processDefinitionKey = "transfer_delegateExpression";
        //业务代码，根据自己的业务用
        String businessKey = "transfer";
        runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, vars);
    }

    /**
     * 使用表达式
     * @param vars 流程参数
     */
    public void transferExpression(Map<String,Object> vars) {
        //流程定义的key,对应请假的流程图
        String processDefinitionKey = "transfer_expression";
        //业务代码，根据自己的业务用
        String businessKey = "transfer";
        runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, vars);
    }

    /**
     * 异常补偿
     * @param vars 流程参数
     */
    public void transferException(Map<String,Object> vars) {
        //流程定义的key,对应请假的流程图
        String processDefinitionKey = "transfer_exception";
        //业务代码，根据自己的业务用
        String businessKey = "transfer";
        runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, vars);
    }
}
